<template>
  <div class="des"> 
    <div class="loading" v-loading="loading" element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)">

    </div>
     <div class="tit">
        {{mdata.name}}
     </div>
     <div class="time">
       <span class="el-icon-view"></span><span>{{mdata.see}}</span> <span>{{mdata.time}}</span>
     </div>
     <div class="con"> 
       <div class="markdown-body">
        <VueMarkdown :source="mdata.con" v-highlight></VueMarkdown>
       </div>
      
     </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref, reactive } from 'vue'
import { findArticleDes,findShareDes,findCodeDes,findLifeDes,findGjDes} from '../api/api'
import VueMarkdown from '@/components/markdown/VueMarkdown.js'
export default defineComponent({
  name: 'des',
  components:{
    VueMarkdown
  },
  props:{
    id:{
      type:String
    },
    type:{
      type:String
    }
  },
  setup(props,ctx) {
     const mdata = reactive({
       name:"",
       time:"",
       con:"",
       see:0
     });
     const loading = ref(true);
     const ajaxfn = function(args?:any):Promise<any>|never{
      if(props.type=='all'){
        return findArticleDes(args);
      }
      if(props.type=='codeShare'){
        return findShareDes(args);
      }
      if(props.type=='codeLife'){
        return findCodeDes(args);
      }
      if(props.type=='lifeWrite'){
        return findLifeDes(args);
      }
      if(props.type=='manger'){
        return findGjDes(args);
      }
      return findArticleDes(args);
    } 
    onMounted(() => {
      
       ajaxfn({id:props.id}).then(((data)=>{
            mdata.name = data[0].name;
            mdata.time = data[0].time;
            mdata.con = data[0].con;
            mdata.see = data[0].see;
            loading.value = false;
        })).catch((e)=>{
           loading.value = false;
        })
    })
    return {
      mdata,
      loading
    }
  },
})
</script>
<style lang="scss" scoped>
  .des{
    background-color: white;
    padding: 0.2rem;
    .loading{
      position: fixed;
      left: 0;
      top: 0;
      bottom: 0;
      width: 100%;
    }
    .tit{
      text-align: center;
      font-size: 0.4rem;
      font-weight: bold;
    }
    .time{
      text-align: right;
      font-size: 0.2rem;
      margin-top: 0.3rem;
      color: rgb(181, 184, 187);
      span:nth-child(1){
        margin-right: 0.1rem;
        color:#409EFF;
      }
    }
    .con{
      margin-top: 0.2rem;
      font-size: 0.2rem;
    }
  }
</style>
